package com.lb.shopguide.util.lb;

import android.os.Build;
import android.os.Environment;
import android.os.StatFs;

import com.blankj.utilcode.util.SDCardUtils;

public class LbSdcardUtil {
    public static long getAvailableByte() {
        if (!SDCardUtils.isSDCardEnable()) return 0;
        StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            return sf.getFreeBytes();
        } else {
            return sf.getAvailableBlocks();
        }
    }

    public static class SDCardInfo {
        boolean isExist;
        long totalBlocks;
        long freeBlocks;
        long availableBlocks;
        long blockByteSize;
        long totalBytes;
        long freeBytes;
        long availableBytes;

        @Override
        public String toString() {
            return "isExist=" + isExist +
                    "\ntotalBlocks=" + totalBlocks +
                    "\nfreeBlocks=" + freeBlocks +
                    "\navailableBlocks=" + availableBlocks +
                    "\nblockByteSize=" + blockByteSize +
                    "\ntotalBytes=" + totalBytes +
                    "\nfreeBytes=" + freeBytes +
                    "\navailableBytes=" + availableBytes;
        }
    }
}
